package com.lx.index.web.feign;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.lx.bean.Result;
import com.lx.dm.entity.Category;
import com.lx.dm.entity.Product;
import com.lx.dm.entity.User;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;

import java.util.Collections;
import java.util.List;

@Component
public class OtherActionImpl implements OtherAction {

    @Override
    public List<Product> queryHots(){
        ObjectMapper mapper = new ObjectMapper();
        try(Jedis jedis = new Jedis("host.docker.internal", 6380)) {
            String key = "cloud_dm_home_hots";
            System.out.println("读取redis缓存数据");
            String json = jedis.get(key);
            List list = Collections.singletonList(mapper.readValue(json, Product.class));
            return list;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }

    @Override
    public List<Category> getCate() {
        return List.of();
    }

    @Override
    public List<Product> queryNews() {
        return List.of();
    }

    @Override
    public Product getProductById(Integer id) {
        return null;
    }

















    //////////////////////////////////////////////
    @Override
    public int add(int a, int b) {
        return a + b + 100;
    }

    @Override
    public Result res(Result r) {
        r.setMsg("熔断");
        return r;
    }

    @Override
    public User user(User user, String myname) {
        user.setUsername("熔断");
        return user;
    }

    @Override
    public String hello(String name) {
        return "hello熔断";
    }
}
